package com.example.makerspace.controller;

import com.example.makerspace.dto.*;
import com.example.makerspace.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.locks.ReadWriteLock;


/**
 * @author River
 * @version 1.0
 * @date 2023/9/25 14:53
 * @description:
 */

@Controller
@ResponseBody
@Api(tags="登入模块")
@RequestMapping("/api")
public class LoginController {
    @Resource
    private LoginService loginService;
    @ApiOperation(value="邮箱验证码接口",notes ="邮箱验证码接口说明")
    @PostMapping("/validateCode")
    public Result validateCode(@RequestBody ValidateCodeDTO validateCodeDTO){
        return loginService.sendEmail(validateCodeDTO);
    }
    @ApiOperation(value="手机验证码接口",notes ="手机验证码接口说明")
    @PostMapping("/CaptchaCode")
    public Result CaptchaCode(@RequestBody CaptchaCodeDTO captchaCodeDTO){
        return  loginService.CaptchaCode(captchaCodeDTO);
    }

    @ApiOperation(value="注册接口",notes ="注册接口说明")
    @PostMapping("/register")
    public Result register(@RequestBody RegistrationDTO registrationDTO){
        return loginService.register(registrationDTO);
    }
    @ApiOperation(value="登入接口",notes ="登入接口说明")
    @PostMapping("/login")
    public Result login(HttpServletRequest request,  @RequestBody LoginDTO loginDTO){
        return loginService.login(request, loginDTO);
    }
    @ApiOperation(value="登入检测接口",notes ="登入接口说明")
    @GetMapping("/loginCheck")
    public Result loginCheck(@RequestParam("username") String username){
        return loginService.loginCheck(username);
    }
    @ApiOperation(value="登入接口2.0接口",notes ="登入接口接口说明")
    @PostMapping("/login1")
    public  Result login1(@RequestBody RegistrationDTO registrationDTO,HttpServletRequest request){
        return loginService.login1(registrationDTO,request);
    }
    @ApiOperation(value="忘记密码接口",notes ="忘记密码接口说明")
    @PostMapping("/forgetPassword")
    public Result forgetPassword(@RequestBody RegistrationDTO registrationDTO){
        return loginService.forgetPassword(registrationDTO);
    }

}
